<?php

namespace App\Model\Account;

use App\Core\BaseModel;

/**
 * CREATE TABLE `ss_statistics` (
 * `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
 * `count_member` int(11) NOT NULL DEFAULT '0' COMMENT '用户数量',
 * `total_score` decimal(12,2) NOT NULL COMMENT '全部用户积分',
 * `rate` decimal(10,2) NOT NULL DEFAULT '1.00' COMMENT '汇率',
 * `available_score` decimal(12,2) NOT NULL COMMENT '可用下单金额',
 * `count_purchase` int(11) NOT NULL DEFAULT '0' COMMENT '全部订单数量',
 * `purchase_amount` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '全部订单金额',
 * `count_unshipping_purchase` int(11) NOT NULL DEFAULT '0' COMMENT '未发货订单数量',
 * `unshipping_purchase_amount` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '未发货订单金额',
 * `count_shipped_purchase` int(11) NOT NULL DEFAULT '0' COMMENT '已发货订单数量',
 * `shipped_purchase_amount` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '已发货订单金额',
 * `count_receipt_purchase` int(11) NOT NULL DEFAULT '0' COMMENT '已收货订单数量',
 * `receipt_purchase_amount` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '已收货订单金额',
 * `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT '创建时间',
 * `created_by` varchar(32) NOT NULL DEFAULT '' COMMENT '创建人员账号',
 * `updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
 * `updated_by` varchar(32) NOT NULL DEFAULT '' COMMENT '最后更新人员账号',
 * `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除[0:未删除，1：已删除]',
 * `deleted_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT '删除时间',
 * PRIMARY KEY (`id`) USING BTREE
 * ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='统计数据';
 */
/**
 * Class StatisticsModel
 * @property int id
 * @property int count_member
 * @property float total_score
 * @property float rate
 * @property float available_score
 * @property int count_purchase
 * @property float purchase_amount
 * @property int count_unshipping_purchase
 * @property float unshipping_purchase_amount
 * @property int count_shipped_purchase
 * @property float shipped_purchase_amount
 * @property int count_receipt_purchase
 * @property float receipt_purchase_amount
 * @property string created_by
 * @property string created_at
 * @property string updated_at
 * @property string updated_by
 * @property int is_delete
 * @property string deleted_at
 *
 * */
class StatisticsModel extends BaseModel
{

    protected $tableName = 'ss_statistics';

    protected $casts = [
        'id'                         => 'integer',
        'count_member'               => 'integer',
        'total_score'                => 'float',
        'rate'                       => 'float',
        'available_score'            => 'float',
        'count_purchase'             => 'integer',
        'purchase_amount'            => 'float',
        'count_unshipping_purchase'  => 'integer',
        'unshipping_purchase_amount' => 'float',
        'count_shipped_purchase'     => 'integer',
        'shipped_purchase_amount'    => 'float',
        'count_receipt_purchase'     => 'integer',
        'receipt_purchase_amount'    => 'float',
        'created_by'                 => 'string',
        'created_at'                 => 'string',
        'updated_at'                 => 'string',
        'updated_by'                 => 'string',
        'is_delete'                  => 'integer',
        'deleted_at'                 => 'string',
    ];

//    汇率
    const RATE = 7.25;

    protected static function onAfterUpdate($model, $res)
    {
        self::delCache('statisticsCache:');
    }

    protected static function onAfterInsert($model, $res)
    {
        self::delCache('statisticsCache:');
    }
}
